package com.itheima.web;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.dto.CheckGroupDto;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckGroupService;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author ：yuanjian
 * @date ：Created in 2020/11/11 14:49
 * @description： 检查项
 */
@RestController
@RequestMapping("/checkgroup")
public class CheckGroupController {

    @Reference
    private CheckGroupService checkGroupService;

    @PostMapping("save")
    @PreAuthorize("hasAuthority('add_checkgroup')")
    public Result save(@RequestBody CheckGroupDto checkGroupDto) {
        checkGroupService.save(checkGroupDto);
        return new Result(true);
    }

    @PostMapping("/findByPage")
    @PreAuthorize("hasAuthority('search_checkgroup')")
    public Result findByPage(@RequestBody QueryPageBean pageBean) {
        return new Result(true, "查询成功!", checkGroupService.findByPage(pageBean));
    }

    @GetMapping("/findCheckItemByCheckGroupId/{id}")
//    @PreAuthorize("hasAuthority('search_checkgroup')")
    public Result findCheckItemByCheckGroupId(@PathVariable("id") Long checkGroupId) {
        return new Result(true, "查询成功!", checkGroupService.findCheckItemByCheckGroupId(checkGroupId));
    }

    @GetMapping("findAll")
//    @PreAuthorize("hasAuthority('search_checkgroup')")
    public Result findAll(){
        return new Result(checkGroupService.findAll());
    }

    @DeleteMapping("/deleteById/{id}")
    @PreAuthorize("hasAuthority('del_checkgroup')")
    public Result deleteById(@PathVariable("id") Long id){
        return new Result( checkGroupService.deleteById(id));
    }
}
